﻿@{
    var listRole = ViewData["Role"] as List<KimPhongCRM.Models.Role>;
    var grid = Html.DevExpress().GridView(settings =>
    {
        settings.Name = "ListUser";
        settings.CallbackRouteValues = new { Controller = "User", Action = "ListUserPartial" };

        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "User", Action = "ListUserPartialAddNew" };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "User", Action = "ListUserPartialUpdate" };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "User", Action = "ListUserPartialDelete" };

        settings.CommandColumn.ButtonType = System.Web.UI.WebControls.ButtonType.Image;
        settings.CommandColumn.SetColVisibleIndex(0);
        settings.CommandColumn.Width = 90;
        settings.CommandColumn.SetHeaderCaptionTemplateContent("Tùy chọn");
        settings.CommandColumn.FixedStyle = GridViewColumnFixedStyle.Left;
        settings.Settings.HorizontalScrollBarMode = ScrollBarMode.Auto;
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.Settings.VerticalScrollBarMode = ScrollBarMode.Hidden;

        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.NewButton.Image.Url = @Url.Content("~/Content/img/icon-24-new.png");
        settings.CommandColumn.NewButton.Image.ToolTip = "New";
        settings.CommandColumn.NewButton.Image.AlternateText = "Thêm";

        settings.CommandColumn.EditButton.Visible = true;
        settings.CommandColumn.EditButton.Image.Url = @Url.Content("~/Content/img/icon-24-edit.png");
        settings.CommandColumn.EditButton.Image.ToolTip = "Eidt";
        settings.CommandColumn.EditButton.Image.AlternateText = "Sửa";

        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.DeleteButton.Image.Url = @Url.Content("~/Content/img/icon-24-delete.png");
        settings.CommandColumn.DeleteButton.Image.ToolTip = "Delete";
        settings.CommandColumn.DeleteButton.Image.AlternateText = "Xóa";

        settings.CommandColumn.UpdateButton.Visible = true;
        settings.CommandColumn.UpdateButton.Image.Url = @Url.Content("~/Content/img/icon-24-ok.png");
        settings.CommandColumn.UpdateButton.Image.ToolTip = "Update";
        settings.CommandColumn.UpdateButton.Image.AlternateText = "Lưu";

        settings.CommandColumn.CancelButton.Visible = true;
        settings.CommandColumn.CancelButton.Image.Url = @Url.Content("~/Content/img/icon-24-cancel.png");
        settings.CommandColumn.CancelButton.Image.ToolTip = "Cancel";
        settings.CommandColumn.CancelButton.Image.AlternateText = "Hủy";


        settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
        settings.SettingsPopup.EditForm.AllowResize = true;
        settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
        settings.SettingsPopup.EditForm.Width = System.Web.UI.WebControls.Unit.Percentage(90);
        settings.SettingsPopup.EditForm.Height = System.Web.UI.WebControls.Unit.Percentage(90);
        settings.SettingsPopup.EditForm.Modal = true;
        settings.SettingsBehavior.ConfirmDelete = true;

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;
        settings.SettingsBehavior.ConfirmDelete = true;

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;

        settings.KeyFieldName = "UserId";

        settings.SettingsPager.Visible = true;
        settings.Settings.ShowGroupPanel = true;
        settings.Settings.ShowFilterRow = true;
        settings.SettingsBehavior.AllowSelectByRowClick = true;

        settings.Columns.Add("UserId");
        settings.Columns.Add(column =>
        {
            column.FieldName = "UserName";
            column.Caption = "UserName";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "Email";
            column.Caption = "Email";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        });
        settings.Columns.Add(column =>
          {
              column.FieldName = "CreateDate";
              column.Caption = "Ngày tạo";
              column.ColumnType = MVCxGridViewColumnType.DateEdit;
              column.Width = 100;
          });
        settings.Columns.Add(column =>
          {
              column.FieldName = "Password";
              column.Caption = "Password";
              column.ColumnType = MVCxGridViewColumnType.TextBox;
              column.Width = 100;
          });

        settings.Columns.Add(column =>
          {
              column.FieldName = "PasswordFormat";
              column.Caption = "PasswordFormat";
              column.ColumnType = MVCxGridViewColumnType.TextBox;
              column.Width = 100;
          });
        settings.Columns.Add(column =>
                {
                    column.FieldName = "PasswordQuestion";
                    column.Caption = "Câu hỏi bí mật";
                    column.ColumnType = MVCxGridViewColumnType.TextBox;
                    column.Width = 100;
                });
        settings.Columns.Add(column =>
                {
                    column.FieldName = "PasswordAnswer";
                    column.Caption = "Trả lời câu hỏi";
                    column.ColumnType = MVCxGridViewColumnType.TextBox;
                    column.Width = 100;
                });
        settings.Columns.Add(column =>
                {
                    column.FieldName = "RoleId";
                    column.Caption = "Nhóm truy cập";
                    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                    foreach (var value in listRole)
                    {
                        comboBoxProperties.Items.Add(value.RoleName, value.RoleId);
                    }
                    comboBoxProperties.ValueType = typeof(Guid);
                    column.Width = 100;
                });

    });
    if (ViewData["EditError"] != null)
    {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.Bind(Model).GetHtml()